<template>
    <div>
        <div class="header" style="background-color: white">
            <el-page-header @back="goBack" content="人事档案">
            </el-page-header>
        </div>
        <el-divider></el-divider>
        <div v-show="ad==1">
            <el-form :model="hremp" label-width="50px" >
                <el-container>
                    <el-form-item label="姓名">
                        <el-input v-model="hremp.empName"  size="small" placeholder="姓名" style="width: 100px"></el-input>
                    </el-form-item>
                    <el-form-item label="手机">
                        <el-input v-model="hremp.empPhone"  size="small" placeholder="手机" style="width: 100px"></el-input>
                    </el-form-item>
                    <el-form-item label="入职">
                        <el-input v-model="hremp.empEntrydate" type="date" size="small" placeholder="入职时间" class="from-control" style="width: 150px"></el-input>
                    </el-form-item>
                    <el-form-item label="身份">
                        <el-select v-model="hremp.empPosition" size="small" placeholder="身份类型" style="width: 100px">
                            <el-option value="">==请选择==</el-option>
                            <el-option value="律师">律师</el-option>
                            <el-option value="实习人员">实习人员</el-option>
                            <el-option value="合伙人">合伙人</el-option>
                            <el-option value="行政主管">行政主管</el-option>
                            <el-option value="股东">股东</el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="到期">
                        <el-input v-model="hremp.empContStartdate" type="date"  size="small" placeholder="合同到期时间" style="width: 150px"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="HrEmpAll" size="small" >查询</el-button>
                        <el-button @click="HrEmpAdd" size="small" >添加人员</el-button>

                    </el-form-item>
                </el-container>

            </el-form>
            <el-table :data="hremps.slice((currentPage-1)*pagesize,currentPage*pagesize)" height="500" border style="width: 100%">
                <el-table-column label="姓名" prop="empName"></el-table-column>
                <el-table-column label="身份" prop="empPosition"></el-table-column>
                <el-table-column label="手机号码" prop="empPhone"> </el-table-column>
                <el-table-column label="入职时间" prop="empEntrydate"> </el-table-column>
                <el-table-column label="合同到期时间" prop="empContStartdate"></el-table-column>
                <el-table-column label="在职状态" >
                    <template scope="scope">
                        <p v-if="scope.row.empWorkstatus=='Y'">在职</p >
                        <p v-if="scope.row.empWorkstatus=='N'">不在职</p >
                    </template>
                </el-table-column>
                <el-table-column label="出生日期" prop="empBirthdate"> </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-dropdown>
                            <el-button type="primary" size="small" >
                                操作<i class="el-icon-arrow-down el-icon--right"></i>
                            </el-button>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item size="small" @click.native="HrEmpAllById(scope)">详情</el-dropdown-item>
                                <el-dropdown-item size="small" @click.native="HrEmpById(scope)">修改</el-dropdown-item>
                                <el-dropdown-item size="small" @click.native="HrByIdWork(scope)">查看工作经历</el-dropdown-item>
                                <el-dropdown-item size="small" @click.native="HrByIdDeree(scope)">查看教育经历</el-dropdown-item>
                                <el-dropdown-item size="small" @click.native="DelHrEmp(scope)">删除</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 20, 40]"
                    :page-size="pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="hremps.length">
            </el-pagination>
        </div>
        <!--添加律师的调用页面-->
        <EmpAll :empById="empById" :tue="tue" :ada="ad" @coles="coles" @AddHrEmp="AddHrEmp" v-if="ad==2"></EmpAll>
        <!--工作经历-->
        <el-dialog
                :visible.sync="dialogVisible" v-if="dialogVisible"
                width="50%">
            <workh :eorkId="eorkId"></workh>
        </el-dialog>
        <el-dialog
                :visible.sync="dialogVisible1" v-if="dialogVisible1"
                width="50%">
            <hrdere :eorkId="eorkId"></hrdere>
        </el-dialog>
    </div>
</template>

<script>
    import workh from "../../gsl/Hr_Workhistory/workhistory"
    import hrdere from "../../gsl/HrDeree/hrderee"
    import EmpAll from "../../gsl/HrEmp/HrEmpAll"
    import hremp from "../../../model/gsl/HrEmp/hremp";
    const hre=hremp.getInstance();
    export default {
        components: {EmpAll,workh,hrdere},
        data() {
            return {
                ad: 1,
                eorkId:"",
                dialogVisible:false,
                dialogVisible1:false,
                currentPage: 1, //初始页
                pagesize: 10,    //    每页的数
                hremps: [],
                hremp: {},//高级查询的数据
                empById: {},//根据id查询的数据
                tue: false,//来分辨详情和添加修改的文本框是否可以修改
            };
        },
        created() {
            this.HrEmpAll();
        },
        methods: {
            // 初始页currentPage、初始每页数据数pagesize和数据data
            handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每页下拉显示数据
            },
            handleCurrentChange: function (currentPage) {
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
            },
            HrEmpAll() {
                hre.list(this.hremp).then((re) => {
                    this.hremps = re.data.data;
                    this.hremp = {}
                })
            },
            //添加，修改 取消后返回到主页面
            coles(s) {
                this.ad = s;
            },

            HrEmpAdd() {
                this.empById = {};
                this.ad = 2;
                this.tue = false;
            },
            // <!--修改方法-->
            HrEmpById(ss) {
                hre.listByid(ss.row.id).then((re) => {
                    this.empById = {};
                    this.empById = re.data.data;
                    this.tue = false;
                    this.ad = 2;
                })
            },
            // <!--查看详情方法-->
            HrEmpAllById(ss) {
                hre.listByid(ss.row.id).then((re) => {
                    this.empById = {};
                    this.empById = re.data.data;
                    this.tue = true;
                    this.ad = 2;
                })
            },
            //删除员工的信息
            DelHrEmp(ss) {
                hre.remove(ss.row.id).then((re) => {
                    if (re.data.data == 1) {
                        this.$message.success({
                            message:'删除成功',
                            duration:1000
                        })
                        this.HrEmpAll();
                        this.ad = 1;
                    } else {
                        alert("删除失败！")
                        this.ad = 2;
                    }
                })
            },
            //弹出工作记录表
            HrByIdWork(work){
                this.dialogVisible=true;
                this.eorkId=work.row.id;
            },
            //弹出教育记录表
            HrByIdDeree(work){
                this.dialogVisible1=true;
                this.eorkId=work.row.id;
            },
            //添加 修改 一起用的方法
            AddHrEmp(hr) {
                console.log(hr)
                if (hr.id) {
                    hre.update(hr).then((re) => {
                        if (re.data.data == 1) {
                            this.$message.success({
                                message:'修改成功',
                                duration:1000
                            })
                            this.HrEmpAll();
                            this.ad = 1;
                        } else {
                            alert("修改失败！")
                            this.ad = 2;
                        }
                    })
                } else {
                    hre.save(hr).then((re) => {
                        if (re.data.data == 1) {
                            this.$message.success({
                                message:'添加成功',
                                duration:1000
                            })
                            this.ad = 1;
                            this.HrEmpAll();

                        } else {
                            alert("添加失败！")
                            this.ad = 2;
                        }
                    })
                }
            },
            goBack(){
                history.back()
            }
        }
    }
</script>

<style scoped>

</style>
